package model;

import java.util.LinkedList;

public class Attribute {
	private String name;
	private double value;
	private LinkedList<Double> valueHistory; /*first will be newest, last - oldest 
	(that's the reason for using a linked list and not a queue)*/
	private int historyLength;
	
	public Attribute(String name, int historyLength) {
		super();
		valueHistory = new LinkedList<Double>();
		setName(name);
		setHistoryLength(historyLength);
		setValue(0);
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getValue() {
		return value;
	}
	public void setValue(double value) {
		/*Updates current value and the history*/
		valueHistory.addFirst(this.value);
		if(valueHistory.size()>historyLength){
			//need to remove an item from the end
			valueHistory.removeLast();
		}
		this.value = value;
	}
	public LinkedList<Double> getValueHistory() {
		return valueHistory;
	}
	public int getHistoryLength() {
		return historyLength;
	}
	public void setHistoryLength(int historyLength) throws RuntimeException {
		/*throws runtime exception if length<0*/
		if(historyLength<0)
			throw new RuntimeException("Can't assign negative value to history length!");
		
		this.historyLength = historyLength;
	}
	
}
